package com.cxl.demo.interceptor;

import com.cxl.demo.interceptor.MyInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public MyInterceptor my(){
        return new MyInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> patterns = new ArrayList();
        patterns.add("/user/login");
        patterns.add("/user/register");
        patterns.add("/data/files/**");
        patterns.add("/file/UploadImage");
        registry.addInterceptor(my()).addPathPatterns("/**").excludePathPatterns(patterns);

    }
}
